package io.kiki.sba.registry.server.data_store.remoting.sessionserver.handler;

import io.kiki.sba.registry.api.Channel;
import io.kiki.sba.registry.common.model.dataserver.GetDataRequest;
import io.kiki.sba.registry.common.model.slot.SlotAccessGenericResponse;
import io.kiki.sba.registry.common.model.store.SubDatum;
import io.kiki.sba.registry.util.StringUtil;


public class GetDataHandler extends BaseGetDataHandler<GetDataRequest> {

    @Override
    public void checkParam(GetDataRequest request) {
        StringUtil.checkNotBlank(request.getDataInfoId(), "GetDataRequest.dataInfoId");
        StringUtil.checkNotBlank(request.getDataCenter(), "GetDataRequest.dataCenter");
        checkClientInterfaceId(request.getClientInterfaceId());
    }

    @Override
    public SlotAccessGenericResponse<SubDatum> doHandle(Channel channel, GetDataRequest request) {
        processClientInterfaceId(channel, request.getClientInterfaceId());

        return processSingleDataCenter(request.getDataCenter(), request.getDataInfoId(), request.getSlotsEpoch(), request.getSlotLeaderEpoch(), request.getAcceptEncodes());
    }

    @Override
    public Class interest() {
        return GetDataRequest.class;
    }
}
